<?php

/**
 * 专辑内容审核
 * 
 * @copyright xinwei
 * @since 2012-03-20
 */

include_once($_SERVER["DOCUMENT_ROOT"] . "/core/inc.php");
include_once($_SERVER["DOCUMENT_ROOT"] . "/core/admin.inc.php");
include_once($_SERVER["DOCUMENT_ROOT"] . "/include/foodv2/inc.php");

$g_cgival = array();
$g_pro = array();
$g_show = array();


function check_cgi_pro()
{
	global $g_cgival, $g_pro, $g_show;
	
	//关键词
	cgi::get($g_cgival["keyword"], "keyword", "");
	$g_cgival["keyword"] = string::un_script_code($g_cgival["keyword"]);
	$g_cgival["keyword"] = string::un_html($g_cgival["keyword"]);
	
	if($g_cgival["keyword"] == "按专辑名称\\作者名称检索")
	{
		$g_cgival["keyword"] = "";
	}
	
	//专辑类目
	cgi::get($g_cgival["class"], "class", "");
	$g_cgival["class"] = intval($g_cgival["class"]);	
	
	//审核状态
	cgi::get($g_cgival["is_verify"], "is_verify", 'all');
	$g_cgival["is_verify"] = string::un_script_code($g_cgival["is_verify"]);
	$g_cgival["is_verify"] = string::un_html($g_cgival["is_verify"]);
	
	//是否推荐
	cgi::get($g_cgival["is_recommend"], "is_recommend", -1);
	$g_cgival["is_recommend"] = intval($g_cgival["is_recommend"]);
	
	//排序规则
	cgi::get($g_cgival["sort_1"], "sort_1", "");
	$g_cgival["sort_1"] = string::un_script_code($g_cgival["sort_1"]);
	$g_cgival["sort_1"] = string::un_html($g_cgival["sort_1"]);
	
	//页码
	cgi::get($g_cgival["p"], "p", 1);
	$g_cgival["p"] = intval($g_cgival["p"]);
	
	//长度
	cgi::get($g_cgival["pc"], "pc", 40);
	$g_cgival["pc"] = intval($g_cgival["pc"]);
	
	cgi::get($g_cgival["sort_2"], "sort_2", "");
	$g_cgival["sort_2"] = string::un_script_code($g_cgival["sort_2"]);
	$g_cgival["sort_2"] = string::un_html($g_cgival["sort_2"]);
	
	cgi::get($g_cgival["sort_3"], "sort_3", "");
	$g_cgival["sort_3"] = string::un_script_code($g_cgival["sort_3"]);
	$g_cgival["sort_3"] = string::un_html($g_cgival["sort_3"]);
	
	cgi::get($g_cgival["sort_4"], "sort_4", "");
	$g_cgival["sort_4"] = string::un_script_code($g_cgival["sort_4"]);
	$g_cgival["sort_4"] = string::un_html($g_cgival["sort_4"]);
	
	cgi::get($g_cgival["sort_5"], "sort_5", "");
	$g_cgival["sort_5"] = string::un_script_code($g_cgival["sort_5"]);
	$g_cgival["sort_5"] = string::un_html($g_cgival["sort_5"]);
	
	cgi::get($g_cgival["sort_6"], "sort_6", "");
	$g_cgival["sort_6"] = string::un_script_code($g_cgival["sort_6"]);
	$g_cgival["sort_6"] = string::un_html($g_cgival["sort_6"]);
	
}

function get_data()
{
	global $g_cgival, $g_pro, $g_show,$config;
	
	$db = new db_food_album();
	$user_db = new db_food_user();
	//$class_db = new db_food_album_class();
	
	// 拿到当前站点的site_id
	$site_id = admin::admin_get_user_site_id();
	
	// 获取全部专辑分类
	$mod_food_album = new mod_food_album();
	$album_class = $mod_food_album->get_food_album_tag_list();

	$data = array();
	$data['album_class'] = $config['food_album_class'];
	
	
	//处理排序条件 - 一次只接收一种排序方式
	$order = '';
	
	//创建时间
	if($g_cgival["sort_1"] == "up")		$order = ' create_time ASC ';
	if($g_cgival["sort_1"] == "down")	$order = ' create_time DESC ';
	//收录
	if($g_cgival["sort_2"] == "up")		$order = ' album_status_count ASC ';
	if($g_cgival["sort_2"] == "down")	$order = ' album_status_count DESC ';
	//被喜欢
	if($g_cgival["sort_3"] == "up")		$order = ' album_love_count ASC ';
	if($g_cgival["sort_3"] == "down")	$order = ' album_love_count DESC ';
	//分享
	if($g_cgival["sort_4"] == "up")		$order = ' album_share_count ASC ';
	if($g_cgival["sort_4"] == "down")	$order = ' album_share_count DESC ';
	//评论
	if($g_cgival["sort_5"] == "up")		$order = ' album_status_count ASC ';
	if($g_cgival["sort_5"] == "down")	$order = ' album_status_count DESC ';
	//更新时间
	if($g_cgival["sort_6"] == "up")		$order = ' update_time ASC ';
	if($g_cgival["sort_6"] == "down")	$order = ' update_time DESC ';
	
	if($order == '')
	{
		$order = ' update_time DESC ';
	}
		
	
	// 按条件获取专辑列表
	$data['album_list'] = $db->admin_get_food_album_list_by_site_id($site_id,$g_cgival["keyword"],$g_cgival["class"],$g_cgival["is_verify"],$g_cgival["is_recommend"],$order,$g_cgival["p"],$g_cgival["pc"]);
	foreach ($data['album_list'] as $i => $val)
	{
		$data['album_list'][$i]["class_name"] = $data['album_class'][$val["album_class"]];
	}

	
	$g_show["data"] = $data;
	
	// Pager 
	$g_show["count"] = $db->admin_get_food_album_count_by_site_id($site_id,$g_cgival["keyword"],$g_cgival["class"],$g_cgival["is_verify"],$g_cgival["is_recommend"]);
	
	$max_page = page_bar::get_page_max($g_show["count"], $g_cgival["pc"], $g_cgival["p"]);
	$page_bar_style = array(
			"curt"		=> $g_cgival["p"],
			"max"		=> $max_page,
			"key"		=> "p",
	);
	
	$g_show["page_bar"] = "<b>{$g_show["count"]}</b> 条记录&nbsp;&nbsp;第{$g_cgival["p"]}页&nbsp;共{$max_page}页&nbsp;" . page_bar::bar3($page_bar_style);
	
	
	//当前参数输出到页面	
	$g_show['args'] = $g_cgival;
	
	//前台URL拼装
	$user_global_config =  user_global_config::get_instance();
	$domain = $user_global_config->get_domain_by_site_id($site_id);			// 当前用户的站点ID
		
	$g_show['url'] = "http://{$domain}"; 
}

$g_show["error"] = 0;
$g_show["errmsg"] = '';
try
{
	admin_check_login();
// 	admin_check_user_priv("foodv2/album_list.php");
	
	check_cgi_pro();
	get_data();
}
catch(Exception $e)
{
	$g_show["error"] = 1;
	$g_show["errmsg"] = $e->getMessage();
}

show_pro();
exit;


function show_pro()
{
	global $g_cgival, $g_pro, $g_show;
	if(isset($_GET['debug']))
		print_r($g_show);
	$smarty = p_get_smarty ();
	$smarty->assign ( 'g_show', $g_show );
	$smarty->display ( "foodv2/album/album_list.html" );
}

?>